<template>
  <div>
    <content-box one="订单管理" two="订单详情">
      <el-row>
        <el-col :span="8">
          <el-input v-model="queryInfo.query" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <br />
        <br />
        <br />

        <el-table :data="orderList" style="width: 100%" border stripe>
          <el-table-column type="index"></el-table-column>
          <el-table-column prop="order_number" label="订单编号">
          </el-table-column>
          <el-table-column prop="order_price" label="订单价格">
          </el-table-column>
          <el-table-column prop="order_pay" label="是否付款"> </el-table-column>
          <el-table-column prop="is_send" label="是否发货"> </el-table-column>
          <el-table-column prop="create_time" label="下单时间">
          </el-table-column>

          <el-table-column label="操作">
            <template slot-scope="scoped">
              <el-button
                icon="el-icon-edit"
                type="primary"
                size="mini"
                @click="showBox"
              ></el-button>
              <el-button
                icon="el-icon-location"
                type="success"
                size="mini"
                @click="showProgress"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
    </content-box>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressVisible"
      width="50%"
      @close="addressDialogClosed"
    >
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
        ><el-form-item label="省市区/县" prop="address1">
          <el-cascader
            :options="cityData"
            v-model="addressForm.address1"
          ></el-cascader
        ></el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 查看物流信息 -->
    <el-dialog
      title="物流进度"
      :visible.sync="progressVisible"
      width="50%"
      @close="progresDialogClosed"
    >
    <!-- 时间线 -->
      <el-timeline >
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.ftime"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 3,
      },
      totol: 0,
      orderList: [],
      addressVisible: false,
      progressVisible: false,
      //地址
      addressForm: {
        address1: [],
        address2: "",
      },
      addressFormRules: {
        address1: {
          required: true,
          message: "请选择省市区/县",
          trigger: "blur",
        },

        address2: {
          required: true,
          message: "请填写详细地址",
          trigger: "blur",
        },
      },
      cityData: cityData,

      progressInfo: [],
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) return this.$message.error("获取失败");
      // console.log(res.data);

      this.orderList = res.data.goods;
      this.totol = res.data.totol;
      console.log(this.orderList);
    },
    //展示修改地址的对话框
    async showBox() {
      console.log(this.addressForm);

      this.addressVisible = true;
    },
    //关闭弹框
    addressDialogClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    async showProgress() {
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      if (res.meta.status !== 200)
        return this.$message.error("获取物流信息失败");
      this.progressInfo = res.data;
      console.log(this.progressInfo);

      this.progressVisible = true;
    },
    progresDialogClosed() {},
  },
};
</script>

<style lang="less" scoped>
.el-cascader {
  width: 100%;
}
</style>